import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, RouterStateSnapshot, Resolve} from '@angular/router';
import {HttpService} from '../services/http.service';
import {map} from 'rxjs/internal/operators';
import {UrlAndOPT} from '../common/url-and-opt.enum';

@Injectable({
  providedIn: 'root'
})
export class BidResolve implements Resolve<any> {

  constructor(
    private service$: HttpService
  ) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any {
    return this.service$.doRequest(UrlAndOPT.bid_bid, {bidIdSign: route.params['bidIdSign']})
      .pipe(
        map(obj => {
          if (obj) {
            return obj['bidInfo'];
          } else {
            return {};
          }
        })
      );
  }

}
